#!/bin/sh
#
# /etc/rc.d/rc.slimserver
#

# Edit this to suit your setup
SLIMSERVER_USER="slimserver"
SLIMSERVER_HOME="/opt/slimserver"
SLIMSERVER_CFG="/etc/slimserver.conf"
SLIMSERVER_LOG="/var/log/slimserver.log"
SLIMSERVER_CACHE="/var/cache/slimserver"
SLIMSERVER_PLAYLISTS="/opt/slimserver/playlists"
SLIMSERVER_ARGS="--daemon --cachedir=$SLIMSERVER_CACHE \
                 --playlistdir=$SLIMSERVER_PLAYLISTS \
                 --prefsfile=$SLIMSERVER_CFG \
                 --logfile=$SLIMSERVER_LOG"
SLIMSERVER_BIN="$SLIMSERVER_HOME/slimserver.pl"


slimserver_start() {
  if [ -x $SLIMSERVER_BIN -a -r $SLIMSERVER_CFG ]; then
    echo "Starting Slimserver..."
    $SLIMSERVER_BIN --user $SLIMSERVER_USER $SLIMSERVER_ARGS
  fi
}

slimserver_stop() {
  echo "Stopping Slimserver..."
  killall slimserver.pl
}

slimserver_restart() {
  slimserver_stop
  sleep 2
  slimserver_start
}


case "$1" in
'start')
  slimserver_start
  ;;
'stop')
  slimserver_stop
  ;;
'restart')
  slimserver_restart
  ;;
*)
  echo "usage $0 start|stop|restart"
esac

